﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Entities;
using Domain.Core;
using System.Transactions;
using Domain.Service;

namespace Infrastructure.Order
{
    public class ProductDetailRepository : BackgroundRepository<ProductDetail>
    {
        public ProductDetailRepository()
        { }
        public ProductDetailRepository(Domain.Core.IUnitOfWork iUnitWork)
            : base(iUnitWork)
        { }
        public override void Add(IEnumerable<ProductDetail> item)
        {
            item.ToList().ForEach(i =>
            {
                base.Add(i);
            });
        }
    }
    public class ProductRepository : BackgroundRepository<Product>, IProductRepository
    {
        IRepository<User_Info> usersRepository;
        public ProductRepository()
        { }

        public ProductRepository(Domain.Core.IUnitOfWork iUnitWork)
            : base(iUnitWork)
        {
            usersRepository = new BackgroundRepository<User_Info>(iUnitWork);
        }



        #region IProductRepository 成员

        public IQueryable<Product> GetProduct()
        {
            var linq = from data1 in base.GetEntities()
                       join data2 in usersRepository.GetEntities() on data1.UserID equals data2.UserID
                       select new Product_Ext
                       {
                           ProductID = data1.ProductID,
                           ProductUser = new ProductUser
                           {
                               Name = data2.RealName,
                           }
                       };
            return linq;
        }

        #endregion
    }
}
